package com.southwind.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.southwind.entity.OrderMaster;
import com.southwind.mapper.OrderMasterMapper;
import com.southwind.service.OrderMasterService;
import com.southwind.util.ResultVOUtil;
import com.southwind.vo.ContentVO;
import com.southwind.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author southwind
 * @since 2023-12-30
 */
@RestController
@RequestMapping("/seller/order/")
public class SellOrderController {


    @Autowired
    private OrderMasterService orderMasterService;
    @Autowired
    private OrderMasterMapper orderMasterMapper;


    @GetMapping("/list/{page}/{size}")
    public ResultVO list(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size
    ) {
        Page<OrderMaster> page1 = new Page<>(page, size);
        Page<OrderMaster> page2 = this.orderMasterService.page(page1);
        ContentVO contentVO = new ContentVO();
        contentVO.setSize(page2.getSize());
        contentVO.setTotal(page2.getTotal());
        contentVO.setContent(page2.getRecords());
        return ResultVOUtil.success(contentVO);
    }

    @PutMapping("/cancel/{orderId}")
    public ResultVO cancel(@PathVariable("orderId") String orderId) {
        QueryWrapper<OrderMaster> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id", orderId);
        OrderMaster one = this.orderMasterService.getOne(queryWrapper);
        one.setOrderStatus(2);
        this.orderMasterService.updateById(one);
        return ResultVOUtil.success(null);
    }

    @PutMapping("/finish/{orderId}")
    public ResultVO finish(@PathVariable("orderId") String orderId) {
        QueryWrapper<OrderMaster> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id", orderId);
        OrderMaster one = this.orderMasterService.getOne(queryWrapper);
        one.setOrderStatus(1);
        this.orderMasterService.updateById(one);
        return ResultVOUtil.success(null);
    }


    /**
     * 柱状图.
     * 需要看懂，后端你这个数据查询的是啥
     * 之后给他封装出来
     */

   // todo 这个分组查询，一下封装数据 ，就这个还有必要写写






}

